/*
 * Copyright (C) 2022 xuexiangjys(xuexiangjys@163.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package cn.kcrx.autoweightapp.fragment.viewmodes

import androidx.lifecycle.LiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.asLiveData
import androidx.lifecycle.viewModelScope
import cn.kcrx.autoweightapp.data.NewCashBoxRecord
import cn.kcrx.autoweightapp.data.NewCashBoxRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.util.*
import javax.inject.Inject

@HiltViewModel
class FragmentDaoTestVM @Inject internal constructor(
  val newCashBoxRepository: NewCashBoxRepository
):ViewModel(){
    private val newCashBoxRecordA= NewCashBoxRecord("100元",100f)
    private val newCashBoxRecordB= NewCashBoxRecord("50元",80f)
    private val newCashBoxRecordC= NewCashBoxRecord("50元",80f)

    val newCashBoxRecords=newCashBoxRepository.getAll().asLiveData()
//    val todayRecords=getTodayDate().asLiveData()

   fun addCashRec()
   {
       newCashBoxRepository.insert(newCashBoxRecordA)
       newCashBoxRepository.insert(newCashBoxRecordB)
    //   newCashBoxRecordC.datatime.add(Calendar.DAY_OF_MONTH, -1)
       newCashBoxRepository.insert(newCashBoxRecordC)
   }
    fun deleteAll(){
        viewModelScope.launch {
            newCashBoxRepository.deleteAll()
        } }
//    private fun getTodayDate(): Flow<List<NewCashBoxRecord>> {
//        val today=Calendar.getInstance()
//        val yesterday=Calendar.getInstance()
//        val mingtian=Calendar.getInstance()
//        yesterday.add(Calendar.DAY_OF_MONTH, -1)
//        mingtian.add(Calendar.DAY_OF_MONTH,1)
//        return  newCashBoxRepository.getTodayRecords(yesterday,today)
//    }
}